package Exercise;

public class factory {
     public static void main(String[] args) { 
        ServiceConsumer(new ServiceFactoryA()); 
        ServiceConsumer(new ServiceFactoryB()); 
    }
    public static void ServiceConsumer(ServiceFactory sf) { 
        Service s = sf.getService(); 
        s.foo(); 
    } //回调 
}
    
    interface Service{ void foo(); } 
   
    interface ServiceFactory{ 
        Service getService(); 
    } 
    
     class ServiceA implements Service{ 
        public void foo() { 
            System.out.println("A: Wall"); 
        } 
    }
    class ServiceB implements Service{
         public void foo() { 
             System.out.println("B: Window");
            }
        } 
    class ServiceFactoryA implements ServiceFactory{ 
        public Service getService() { 
            return new ServiceA(); 
        } 
    }
     class ServiceFactoryB implements ServiceFactory{ 
         public Service getService() {return new ServiceB(); 
        }
    }
}